import 'package:flutter/material.dart';
import 'CommentPage.dart';
import 'AskPage.dart';

// ignore: must_be_immutable
class TalkPage extends StatefulWidget {
  String title;

  TalkPage({this.title});

  @override
  State<StatefulWidget> createState() {
    return TalkState();
  }

}

class TalkState extends State<TalkPage> with SingleTickerProviderStateMixin {
  TabController _tabController;
  List<Widget> viewList = [];

  @override
  void initState() {
    super.initState();
    viewList.add(AskPage());
    viewList.add(CommentPage());
    _tabController = new TabController(vsync: this, initialIndex: 0, length: 2);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color(0xff313131),
        title: Text(widget.title),
        bottom: TabBar(
            isScrollable: false,//是否可滑动
            unselectedLabelColor: Colors.white,//未选中按钮颜色
            labelColor: Colors.white,//选中按钮颜色
            labelStyle: TextStyle(fontSize: 16),//文字样式
            indicatorSize: TabBarIndicatorSize.label,//滑动的宽度是根据内容来适应,还是与整块那么大(label表示根据内容来适应)
            indicatorWeight: 2.0,//滑块高度
            indicatorColor: Colors.black87,//滑动颜色
            indicatorPadding: EdgeInsets.only(bottom: 1),//与底部距离为1
            controller: _tabController,
            tabs: <Widget> [
              new Tab(
                text: '单读问',
              ),
              new Tab(
                text: '读者论',
              )
            ]
        )
      ),
      body: TabBarView(
        controller: _tabController,
        children: viewList
      )
    );
  }

}